package cn.gz.demo.ui;


import android.os.Bundle;
import android.widget.LinearLayout;

import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.LinearLayoutManager;

import java.util.ArrayList;
import java.util.List;

import cn.gz.demo.R;
import cn.gz.demo.adapter.RollRecylerViewListAdapter;
import cn.gz.demo.databinding.RollRecylerViewBinding;
import cn.gz.demo.ui.base.BaseActivity;

/**
 * Created by Liuyz on 2017/12/7.
 */
public class RollRecylerViewActivity extends BaseActivity {
    RollRecylerViewBinding binding;
    private RollRecylerViewListAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = DataBindingUtil.setContentView(this, R.layout.activity_roll_recylerview);
        initView();
    }

    private void initView() {
        List<String> list = new ArrayList<>();
        for (int i = 0; i < 5; ) {
            list.add(" Item: " + ++i);
        }

        binding.recyclerview.setLayoutManager(new LinearLayoutManager(context, LinearLayout.VERTICAL, false));
        adapter = new RollRecylerViewListAdapter(context, list);
        binding.recyclerview.setAdapter(adapter);
        adapter.notifyDataSetChanged();
//        if (true) //保证itemCount的总个数宽度超过屏幕宽度->自己处理
        binding.recyclerview.start();
    }
}
